TDZ (Temporal Dead Zone)


Posted by YongChenSu on 2020-12-09

var 宣告

function test(){
  console.log(a)
  var a = 1
}
test()
// undefined

let 或 const 宣告

用 let 或 const 宣告一樣有 hoisting 但在賦值之前無法存取,這區間稱為 TDZ

function test(){
  console.log(a)
  var a = 1
}
test()
// Uncaught ReferenceError: Cannot access 'a' before initialization


參考資源


#程式導師實驗計畫第四期 #前端 #temporal dead zone







Related Posts

COSCUP 2022 信箱爆炸了

COSCUP 2022 信箱爆炸了

繞過 phpMyAdmin 建立資料庫與表格

繞過 phpMyAdmin 建立資料庫與表格

ASP.NET Core  Web API 入門教學 - 資料庫連線設定 Database First,Scaffold-DbContext Build Failed解決方式

ASP.NET Core Web API 入門教學 - 資料庫連線設定 Database First,Scaffold-DbContext Build Failed解決方式


Comments